package org.codeart.prototype;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 具体原型类
 * 实现表示接口Cloneable
 */
@Data
@AllArgsConstructor
@Accessors(chain = true)
public class ConcretePrototype implements Cloneable, Serializable {

    private Person person;

    public void show() {
        System.out.println("人的姓名: " + person.getName());
    }

    public ConcretePrototype() {
        System.out.println("具体原型对象创建成功");
    }

    @Override
    protected ConcretePrototype clone() throws CloneNotSupportedException {
        System.out.println("克隆对象复制成功");
        return (ConcretePrototype) super.clone();
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        ConcretePrototype c1 = new ConcretePrototype();
        Person p1 = new Person("洛必达");
        c1.setPerson(p1);
        ConcretePrototype c2 = c1.clone();
        System.out.println(c1 == c2);
        System.out.println(c1.getPerson() == c2.getPerson());


    }
}
